<?php

class_exists("MPVehicles") || require("class.MPVehicles.php");
class_exists("MPTrips") || require("class.MPTrips.php");

class MPOverview
{
	private $m_company_id;
	private $m_vehicles;
	private $m_tripLists;
	
	public function __construct($companyID)
	{
		$this->m_company_id = $companyID;
		$this->m_tripLists = array();
	}
	
	public function load_from_db($db)
	{
		$this->m_vehicles = new MPVehicles($this->m_company_id);
		$this->m_vehicles->load_from_db($db);
		
		foreach( $this->m_vehicles->get_vehicles() as $vehicle )
		{
			$tripsTemp = new MPTrips($vehicle->get_registration());
			$tripsTemp->load_from_db($db);
			$this->m_tripLists[] = $tripsTemp;
		}
	}
	
	public function get_html_vehicles()
	{
		$output_html = <<<HTM
			<h1>Vehicles</h1>
			<div class="table-vehicles">
				<div class="row">
					<div class="column-1 colour-secondary">Registration</div>
					<div class="column-2 colour-secondary">Min Capacity</div>
					<div class="column-3 colour-secondary">Max Capacity</div>
					<div class="column-4 colour-secondary">Wheelchair Seats</div>
				</div>
HTM;
		
		$rowHighlight = "nonexistent-class";
		
		foreach( $this->m_vehicles->get_vehicles() as $vehicle )
		{
			$reg = $vehicle->get_registration();
			$mincap = $vehicle->get_min_capacity();
			$maxcap = $vehicle->get_max_capacity();
			$wheelcap = $vehicle->get_wheelchair_capacity();
			
			if($rowHighlight=="")
				$rowHighlight = " colour-tietary";
			else $rowHighlight = "";
						
			$output_html .= <<<HTM
<div class="row">
					<div class="column-1$rowHighlight">$reg</div>
					<div class="column-2$rowHighlight">$mincap</div>
					<div class="column-3$rowHighlight">$maxcap</div>
					<div class="column-4$rowHighlight">$wheelcap</div>
				</div>
HTM;
		}
		
		$output_html .= <<<HTM
		
			</div>
HTM;
		
		return $output_html;
	}
	
	public function get_html_trips()
	{
		$output_html = <<<HTM
			<h1>Trips</h1>
			<div class="table-trips">
				<div class="row">
					<div class="column-1 colour-secondary">Vehicle Reg</div>
					<div class="column-2 colour-secondary">Origin</div>
					<div class="column-3 colour-secondary">Destination</div>
					<div class="column-4 colour-secondary">Seats Used</div>
				</div>
HTM;
		
		$rowHighlight = "nonexistent-class";
		
		foreach( $this->m_tripLists as $trips ) {
			$reg = $trips->get_vehicle();
			
			foreach( $trips->get_trips() as $trip )
			{
				$orig = $trip->get_origin();
				$dest = $trip->get_destination();
				$used = $trip->get_seats_used();
				
				if($rowHighlight=="")
					$rowHighlight = " colour-tietary";
				else $rowHighlight = "";
							
				$output_html .= <<<HTM
<div class="row">
					<div class="column-1$rowHighlight">$reg</div>
					<div class="column-2$rowHighlight">$orig</div>
					<div class="column-3$rowHighlight">$dest</div>
					<div class="column-4$rowHighlight">$used</div>
				</div>
HTM;
			}
		}
		
		$output_html .= <<<HTM
		
			</div>
HTM;
		
		return $output_html;
	}
	
	public function get_html()
	{
		$output_html = "";
		
		$output_html .= $this->get_html_vehicles();
		$output_html .= '<div style="height:30px;"></div>';
		$output_html .= $this->get_html_trips();
		
		return $output_html;
	}
}

?>
